package net.lzzy.practices.web.models;

import lombok.Getter;
import lombok.Setter;
import net.lzzy.practices.entities.BaseEntity;
import net.lzzy.practices.entities.Option;
import net.lzzy.practices.entities.Result;

import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

/**
 * @author  Jaymo on 2022/6/8
 */
@Getter
@Setter
public class VmResult {
    private UUID id;
    private  int what;
    private  UUID qid;
    private  int ordinal;
    private  UUID sid;
    private  String avatar;
    private  String name;
    private List<UUID> optionIds;
    private  List<UUID> answerIds;
    private Date commitTime;

    public  VmResult(Result result){
        id = result.getId();
        what = result.what();
        qid = result.getQuestion().getId();
      ordinal = result.getQuestion().getOrdinal();
      sid = result.getStudent().getId();
      avatar = result.getStudent().getNickName();
      optionIds = result.getOptions().stream().map(BaseEntity::getId).collect(Collectors.toList());
       answerIds = result.getQuestion().getOptions().stream().filter(Option::isAnswer).map(BaseEntity::getId).collect(Collectors.toList());
       commitTime = result.getCommitTime();
    }

}
